// Zepto
var $ = require('./components/zepto/zepto');
require('./components/zepto/event');
require('./components/zepto/ajax');
require('./components/zepto/form');
require('./components/zepto/ie');
require('./components/zepto/touch');

module.exports = $;

// 引入Swiper

var Swiper = require('./components/swiper/swiper.min.js');
var swiperAnimate = require('./components/swiper/swiper.animate1.0.2.min.js');
var swiper = new Swiper ('.swiper-container', {
	pagination: '.swiper-pagination',
    direction: 'vertical',
    slidesPerView: 1,
    paginationClickable: true,
    spaceBetween: 30,
    mousewheelControl: true,
  onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
    swiperAnimate.swiperAnimateCache(swiper); //隐藏动画元素 
    swiperAnimate.swiperAnimate(swiper); //初始化完成开始动画
  }, 
  onSlideChangeEnd: function(swiper){ 
    swiperAnimate.swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
  } 
})

var interval  = setInterval(function(){
    if(document.readyState === 'complete'){   	
        clearInterval(interval);
        $("#loading").hide();
        $(".swiper-container").show();
        swiper.updateContainerSize(); // 万分重要
        swiper.updateSlidesSize(); // 万分重要
    }else{
        $("#loading").show();
    }
})
var num=0;
setInterval(function(){
	num++;
	if(num==360){
		num=0
	}
	$('.svg').css({'transform':'rotate('+num+'deg)'})
},10);

$(".swiper-container").show();
$("#mainContainer").hide();

var len;
var IScroll = require('./components/iscroll/iscroll');
//// jquery/zepto
	$("#enter").tap(function(){
	    $(".swiper-container").hide();
	    $("#mainContainer").show().trigger('click');
	})
	$("#footer ul li").tap(function(){
		$('#add').show();
		$('#cont').hide();
	    var apiTarget = $(this).attr('id');
	    $(this).children('i').addClass('fontCol');
	    $(this).children('i').css({'color':'green'});
	    $(this).siblings().children('i').css({'color':'#ccc'});
	    $(this).siblings().children('i').removeClass('fontCol');
	    $('#header .headtext').text($(this).text());
	    var apiUrl = "http://localhost:8000/api/" + apiTarget + ".php";	
	  $.ajax({
	      type:'GET',
	      url:apiUrl,
//	      async: false,
	      success:function(data){
	          var html = "";
            if (data.length>9) {
            	len=9
            } else{
            	len=data.length
            }
            for(var i=0;i<len;i++){
                html +='<li>'+
					'<div class="img"><img src="'+data[i].images+'"/></div>'+
					'<div class="text">'+data[i].name+'</div>'+
				'</li>';
            }
            $("#scroller ul").html(html);
	      }
	  })
	
	})
	
	$.ajax({
	        type:'GET',
	        url:'http://localhost:8000/api/skill.php',
	        dataType:'json',
//	        async: false,
	        success:function(data){
	            var html = "";
	            if (data.length>9) {
	            	len=9
	            } else{
	            	len=data.length
	            }
	            for(var i=0;i<len;i++){
	                html +='<li>'+
								'<div class="img"><img src="'+data[i].images+'"/></div>'+
								'<div class="text">'+data[i].name+'</div>'+
							'</li>';
	            }
	            $("#scroller ul").html(html);
	            	
	        }
	    })
	
		
		$('#add').on('tap','li',function(){
			var apiTarget = $("#footer li .fontCol").parent().attr('id');
	        var apiUrl = "http://localhost:8000/api/" + apiTarget + ".php";
	        if (apiTarget!='skill') {
				$('#add').hide();
				$('#cont').show();
			}
	        addindex=$(this).index()
			$.ajax({
		      type:'GET',
		      url:apiUrl,		      
		      success:function(data){
		      	if (apiTarget=='work') {
		      		var html = "";	
		            html +='<img class="animated flipInX" src="'+data[addindex].images+'" alt="" />'+
						'<p class="animated bounceInLeft">单位性质：<span>'+data[addindex].category+'</span></p>'+
						'<p class="animated bounceInLeft">单位名称：<span>'+data[addindex].name+'<span></p>'+
						'<p class="animated bounceInLeft">工作时间：<span>'+data[addindex].time+'<span></p>'+
						'<p class="animated bounceInLeft">工作岗位：<span>'+data[addindex].posts+'<span></p>'+
						'<p class="animated bounceInLeft">工作年限：<span>'+data[addindex].peoples+'<span></p>'+
						'<p class="animated bounceInLeft">项目：<span>'+data[addindex].projects+'<span></p>'
	            	$("#cont").html(html);
		      	}
		      	if (apiTarget=='project') {
		      		var html = "";	
		            html +='<img class="animated flipInX" src="'+data[addindex].images+'" alt="" />'+
						'<p class="animated bounceInLeft">单位性质：<span>'+data[addindex].category+'</span></p>'+
						'<p class="animated bounceInLeft">单位名称：<span>'+data[addindex].name+'<span></p>'+
						'<p class="animated bounceInLeft">工作时间：<span>'+data[addindex].description+'<span></p>'+
						'<p class="animated bounceInLeft">工作岗位：<span>'+data[addindex].detail+'<span></p>'+
						'<p class="animated bounceInLeft">工作年限：<span>'+data[addindex].tech+'<span></p>'
	            	$("#cont").html(html);
		      	}
		          
		      }
		 })	
		})
		$('#header').tap(function(){
    		$('#add').show();
			$('#cont').hide();
    	})
	    myScroll = new IScroll('#wrapper', { mouseWheel: true });
	    document.addEventListener('touchmove', function (e) { e.preventDefault()},false); 
    	



//var interval  = setInterval(function(){
//	console.log(1111)
//  if(document.readyState === 'complete'){   	
//      clearInterval(interval);
//      $("#loading").hide();
//      $(".swiper-container").show();
//      swiper.updateContainerSize(); // 万分重要
//      swiper.updateSlidesSize(); // 万分重要
//  }else{
//      $("#loading").show();
//  }
//},10)